<!--
* description: 采购管理-欠拨修改
* author: hzm
* createdDate: 2021-1-22
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="dynamicApiConfigs"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :callback-obj="callbackObj"
      :dynamic-is-show-select="true"
      :dynamic-is-init-table="true"
      :dynamic-is-fix-choose="false"
      :dynamic-is-fix-index="false"
      :dynamic-is-show-more-btn="true"
      :dynamic-api-style="'restful'"
    >
      <!--      1 代表结案  0 代表欠拨-->
      <template #isEffective="scope">
        <el-checkbox
          v-model="scope.row.isEffective"
          true-label="1"
          false-label="0"
          :disabled="scope.row.isEffective === '0'"
          @change="underdiaStatusChange($event, scope.row)"
        />
      </template>
      <template #underdialQty="{row}">
        <el-input-number
          v-model="row['underdialQty']"
          :step="1"
          :min="0"
          step-strictly
        />
      </template>
    </one-table-template>
  </div>
</template>

<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import { orgApis } from '@/api/paSparePartsManagement'

export default {
  name: 'DialToModify',
  components: {
    OneTableTemplate
  },
  mixins: [oneTableWithViewTemplateMixins],
  data() {
    return {
      selectiondata: [],
      dynamicApiConfigs: orgApis.queryUnderdialChangeInfo,
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'dlrCode',
              label: '网点编码',
              align: 'center'
            },
            {
              prop: 'dlrShortName',
              label: '网点名称',
              align: 'center'
            },
            {
              prop: 'partNo',
              label: '备件编码',
              align: 'center'
            },
            {
              prop: 'partName',
              label: '备件名称',
              align: 'center'
            },
            {
              prop: 'purOrderTypeCn',
              label: '订单类型',
              align: 'center'
            },
            {
              prop: 'purOrderCode',
              label: '订单编号',
              align: 'center'
            },
            {
              prop: 'purQty',
              label: '订单数量',
              align: 'center'
            },
            {
              prop: 'underdialQty',
              label: '欠拨数量',
              align: 'center',
              isSlot: true,
              width: 150
            },
            {
              prop: 'underdiaDate',
              label: '欠拨产生日期',
              align: 'center'
            },
            {
              prop: 'isEffective',
              label: '是否有效欠拨',
              align: 'center',
              isSlot: true
            },
            {
              prop: 'underdiaStatusCn',
              label: '欠拨状态',
              align: 'center'
            },
            {
              prop: 'modifyReason',
              label: '修改原因',
              align: 'center',
              isShowLabel: false,
              isComponent: true,
              comps: [
                {
                  compKey: 'audit',
                  codeField: 'modifyReason',
                  component: () => import('@/components/org/commonInput')
                }
              ]
            }
          ],
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            // 库存状态
            {
              compKey: 'compKey1',
              labelName: '网点编码：',
              codeField: 'dlrCode',
              lookuptype: 'VE0212',
              component: () => import('@/components/ve/multipleSearchInput'),
              type: 'inputText',
              isMust: true,
              dataToObject: {
                oFields: 'dlrCode,dlrShortName',
                // 控制弹窗页面 搜索 网格 元素
                tableComponents: [
                  {
                    compKey: 'compKey1',
                    labelName: '网点编码：',
                    codeField: 'dlrCode',
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  },
                  {
                    compKey: 'compKey2',
                    labelName: '网点名称：',
                    codeField: 'dlrShortName',
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  }
                ],
                tableCols: [
                  {
                    prop: 'dlrCode',
                    label: '网点编码'
                  },
                  {
                    prop: 'dlrShortName',
                    label: '网点名称'
                  }
                ],
                formField: {
                  dlrShortName: '',
                  dlrCode: ''
                },
                returnField: {
                  prop: 'dlrCode',
                  label: '网点编码'
                },
                api: orgApis.queryOrgDlrCodes
              },
              span: 6
            },
            // 车辆状态
            {
              compKey: 'compKey4',
              labelName: '网点名称：',
              codeField: 'dlrShortName',
              lookuptype: 'VE0207',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              span: 6
            },
            // 入库仓库
            {
              compKey: 'compKey5',
              labelName: '订单编码：',
              codeField: 'purOrderCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              span: 6
            },
            // 审核状态
            {
              compKey: 'compKey6',
              labelName: '订单类型：',
              codeField: 'purOrderType',
              textField: 'lookupValueName',
              customObj: {
                api: orgApis.queryDropDownList
              },
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey7',
              labelName: '欠拨日期：',
              codeField: 'beginDate,endDate',
              component: () =>
                import('@/components/org/datePicker/andtDatePicker'),
              type: 'YYYY-MM-DD',
              // dataToObject: { timer: true, thirtyTime: true, hhmmss: true },
              format: 'yyyy-MM-dd',
              dateOptionsType: '0',
              isMul: false,
              isMust: false,
              span: 6
            },
            {
              compKey: 'compKey8',
              labelName: '备件编码：',
              codeField: 'partNo',
              lookuptype: 'VE0212',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false,
              span: 6
            },
            {
              compKey: 'compKey9',
              labelName: '备件名称：',
              codeField: 'partName',
              lookuptype: 'VE0212',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false,
              span: 6
            },
            {
              compKey: 'compKey10',
              labelName: '欠拨状态：',
              codeField: 'underdiaStatus',
              textField: 'statusText',
              lookuptype: 'VE0212',
              component: () => import('@/components/org/commonSelect'),
              oFields: 'statusId,statusText',
              options: [
                { statusId: '1', statusText: '结案' },
                { statusId: '0', statusText: '欠拨' }
              ],
              type: 'dropdownList',
              isMust: false,
              span: 6
            }
          ],
      tableButtons: [
        {
          conmpKey: 'btenKey1',
          type: 'primary',
          size: 'small',
          text: '查询',
          clickEvent: () => this.queryTable(1),
          position: 'right'
        },
        {
          conmpKey: 'btenKey2',
          type: '',
          size: 'small',
          text: '提交',
          clickEvent: () => this.distributor(),
          position: 'right'
        },
        {
          conmpKey: 'btenKey3',
          type: '',
          size: 'small',
          text: '重置',
          clickEvent: () => this.reset(),
          position: 'right'
        }
      ],
      formField: this.$utils.getFormField(this, {
        dlrCode: '',
        dlrShortName: '',
        purOrderCode: '',
        purOrderType: '',
        underdiaDate: '',
        partNo: '',
        partName: '',
        underdiaStatus: '',
        beginDate: '',
        endDate: ''
      }),
      callbackObj: {
        // 手动勾选网格时，拿到勾选网格的数据
        onCheckSelect: (selection, row) => {
          this.selectiondata = selection
        },
        onCheckSelectAll: (selection) => {
          this.selectiondata = selection
        }
      }
    }
  },
  mounted() {
    this.queryTable(1)
  },
  methods: {
    underdiaStatusChange(val, row) {
      // if (val === '1') {
      //   row['underdiaStatusCn'] = '结案'
      // } else {
      //   row['underdiaStatusCn'] = '欠拨'
      // }
    },
    distributor() {
      const that = this
      const infoQue = this.selectiondata
      // this.selectiondata.forEach(function(val, index) {
      //   infoQue.push({
      //     modifyReason: val.modifyReason,
      //     underdialOrderId: val.underdialOrderId
      //   })
      // })
      if (infoQue.length == 0) {
        this.$message({
          message: '请勾选数据后进行提交',
          type: 'success',
          duration: 2000
        })
      } else {
        const queryObj = {
          apiConfig: orgApis.submitUnderdialChange,
          // 条件/实体参数（变量），根据typeParam中的定义配置
          variables: {
            // 当前中台使用的名称有dataInfo、info，具体查看API文档
            dataInfo: infoQue
          }
        }
        // 转换了中台请求格式数据
        var paramD = that.$getParams(queryObj)
        // 调用中台API方法（可复用）
        that.$requestAPI(paramD).then((response) => {
          if (response.result === '0') {
            return
          }
          var getResult = response
          if (getResult.result === '1') {
            that.$message({
              message: '提交成功',
              type: 'success',
              duration: 2000
            })
            // 重置表单
            // that.resetRight(tableRef)
            that.queryTable(1)
            this.selectiondata = []
            // 重新加载
            // that.queryTable(1)
          } else {
            that.$message({
              message: getResult.msg,
              type: 'warning',
              duration: 2000
            })
          }
        })
        // }
      }
    }
  }
}
</script>

<style>
</style>
